<template>
    <div>
        <el-card class="box-card">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
              <span v-if="getMyCollapse" @click="openMenu">
                <i class="el-icon-s-unfold"></i>
              </span>
                    <span v-else  @click="closeMenu">
                         <i class="el-icon-s-fold"></i>
              </span>
                </el-breadcrumb-item>
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item><a href="/">活动管理</a></el-breadcrumb-item>
                <el-breadcrumb-item>活动列表</el-breadcrumb-item>
                <el-breadcrumb-item>活动详情</el-breadcrumb-item>
            </el-breadcrumb>
        </el-card>

        <el-card class="box-card">
            <div style="text-align: left">
                <span >
                    <i class="el-icon-search"></i>
                    <span>筛选搜索</span>
                </span>
                <el-button size="mini" style="margin-left:5px;float: right" type="primary" icon="el-icon-search" @click="onSubmit">查询结果</el-button>
                <el-button size="mini" style="float: right">重置</el-button>
            </div>
            <div style="margin-top: 20px">
                <el-form :inline="true" align="left" :model="formInline" class="demo-form-inline" size="mini">
                    <el-form-item label="输入搜索">
                        <el-input v-model="formInline.name" placeholder="商品名称"></el-input>
                    </el-form-item>
                    <el-form-item label="商品货号">
                        <el-input v-model="formInline.user" placeholder="商品货号"></el-input>
                    </el-form-item>
                    <el-form-item label="商品分类">
                        <el-input v-model="formInline.user" placeholder="商品名称"></el-input>
                    </el-form-item>
                    <el-form-item label="商品品牌">
                        <el-input v-model="formInline.user" placeholder="商品品牌"></el-input>
                    </el-form-item>
                    <el-form-item label="上架状态">
                        <el-input v-model="formInline.user" placeholder="商品名称"></el-input>
                    </el-form-item>
                    <el-form-item label="审核状态">
                        <el-input v-model="formInline.user" placeholder="商品名称"></el-input>
                    </el-form-item>
                </el-form>
            </div>

        </el-card>

        <el-card class="box-card">
            <i class="el-icon-s-order"></i>
            <span>数据列表</span>
            <el-button size="mini" style="float: right">添加</el-button>
        </el-card>

        <el-card class="box-card">

            <el-table
                    @selection-change="handleSelectionChange"
                    :data="tableData"
                    style="width: 100%">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column
                        label="图片"
                >
                    <template #default={row}>
                        <img width="100" height="100" :src="row.pic"/>
                    </template>
                </el-table-column>
                <el-table-column
                        label="商品名"
                        prop="name">
                </el-table-column>
                <el-table-column
                        label="状态"
                        prop="name">
                    <template #default={row}>
                        <p>上架：
                            <el-switch
                                    v-model="row.publishStatus"
                                    active-color="#13ce66"
                                    :active-value="1"
                                    :inactive-value="0"
                                    inactive-color="#ff4949">
                            </el-switch>
                        </p>
                        <p>新品：
                            <el-switch
                                    v-model="row.newStatus"
                                    active-color="#13ce66"
                                    :active-value="1"
                                    :inactive-value="0"
                                    inactive-color="#ff4949">
                            </el-switch>
                        </p>
                        <p>推荐：
                            <el-switch
                                    v-model="row.recommandStatus"
                                    active-color="#13ce66"
                                    :active-value="1"
                                    :inactive-value="0"
                                    inactive-color="#ff4949">
                            </el-switch>
                        </p>
                    </template>
                </el-table-column>
                <el-table-column
                        label="操作"
                        align="right">
                    <template #default="scope">
                        <el-button
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="mycurrent"
                    :page-sizes="[3, 5, 10, 15]"
                    :page-size="mysize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="mytotal">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: "Main",
        computed: {
            getMyCollapse () {
                return this.$store.state.myCollapse
            }
        },
        created(){
            console.log('初始化商品列表...');
            this.getProListPage({})
        },
        data: function() {
            return {
                mycurrent:2,
                mysize:5,
                mytotal:0,
                multipleSelection:[],
                value:true,
                myOpeneds:['1','1-4'],
                myCollapse:false,
                visible: false,
                formInline: {
                    name:'',
                    user: '',
                    region: ''
                },
                tableData: [],
                search: ''
            }
        },
        methods: {
            getProListPage(data){
                this.$axios.get('http://localhost:8080/products/pms-product/getPmsProductListPage',
                    {
                        params: data
                    }
                )
                    .then(response => {
                        this.tableData = response.data.records
                        this.mycurrent = response.data.current
                        this.mysize = response.data.size
                        this.mytotal = response.data.total
                    })
                    .catch(function (error) { // 请求失败处理
                        console.log(error);
                    });
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
                console.log(val);
            },
            openMenu(){
                console.log('openMenu');
                this.$store.commit('openMenu')
                console.log(this.$store.state.myCollapse)
            },
            closeMenu(){
                console.log('closeMenu');
                this.$store.commit('closeMenu')
                console.log(this.$store.state.myCollapse)
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                const data ={current:val,size:this.mysize}
                this.getProListPage(data);
            },
            handleEdit(index, row) {
                console.log(index, row);
            },
            handleDelete(index, row) {
                console.log(index, row);
                alert("删除："+this.multipleSelection)
            },
            onSubmit() {
                console.log('submit!');
                console.log(this.formInline);

            },
            handleOpen(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log(key, keyPath);
            }
        }
    }
</script>

<style scoped>

</style>
